<% default_public = @member.default_public %>
<div id="content" class="page_subscribe">
<div id="content-inner">
<% if @feeds.size %>

<h2>Subscribe Feed</h2>
<!-- <form action="/subscribe/confirm" method="post" name="subscribe" onsubmit="subscribe_submit.call(this,event)">-->

<% form_tag({ :controller => :subscribe, :action => "confirm", :id => "" }, {:name => "subscribe", :onsubmit => "subscribe_submit.call(this,event)" }) do %>

<div class="subscribe_candidates">
	<h3>You can subscribe to</h3>
	<input type="hidden" name="url" value="<%=h params[:url] %>" id="target_url">
	<input type="hidden" name="register" value="1">
	<input type="hidden" name="ApiKey" value="<%= session.session_id %>">
	<% not_subscribed = 0 %>
	<% seen = {} %>
	<ul id="feed_candidates">
<% @feeds.each_with_index do |feed, i| %>
	<% next if seen.has_key?(feed.feedlink) %>
	<% seen[feed.feedlink] = true %>
	<% if subs = feed[:subscribe_id] %>
		<li class="list<% if i == 0 %> list-first<% end %>">
			<a class="subscribe_list" style="background-image:url('/icon/<%= feed.id %>')" href="<%=h feed.link %>"><%=h feed.title %></a>
			<span class="subscriber_count"><%= users_link(feed) %></span>
			<span class="subscribed">［subscribed］</span>
			<button class="subs_edit" rel="edit:<%= subs %>" onkeydown="subs_edit.call(this,event)" onmousedown="subs_edit.call(this,event)" onclick="return false">Edit</button>
			<button class="subs_delete" id="sub_<%= subs %>" onclick="subs_delete.call(this,event)">Delete</button>
			<br />
			<a href="<%=h feed.feedlink %>" class="feedlink"><%=h feed.feedlink %></a>
		</li>
	<% else %>
		<li class="list<% if i == 0 %> list-first<% end %>">
			<input type="checkbox" name="check_for_subscribe[<%= not_subscribed %>]" value="<%=h feed.feedlink %>"<% if @feeds.size == 1 || i == 0 %> checked<% end %>>
			<input type="hidden" name="feedlink" value="<%=h feed.feedlink %>" />
			<a class="subscribe_list" style="background-image:url('/icon/<%= feed.id %>')" href="<%=h feed.link %>"><%=h feed.title %></a>
			<span class="subscriber_count"><%= users_link(feed) %></span><br />
			<a href="<%=h feed.feedlink %>" class="feedlink"><%=h feed.feedlink %></a>
		</li>
		<% not_subscribed = not_subscribed + 1 %>
	<% end %>
<% end %>
	</ul>
</div>

<% if not_subscribed > 0 %>
<div class="subscribe_option">
	<h3>Options</h3>
	<table>
		<tr><th>Folder</th>
		<td>
			<select name="folder_id" onchange="folder_change.call(this,event)">
			<option value="0" selected>Leave it uncategorized</option>
			<option value="-">Create new folder</option>
			<% @member.folders.each do |folder| %>
			<option value="<%= folder.id %>"><%=h folder.name %></option>
			<% end %>
			</select>
		</td></tr>
		<tr><th>Rating</th>
		<td>
			<select name="rate">
				<option value="0" selected>0</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				<option value="4">4</option>
				<option value="5">5</option>
			</select>
		</td>
		</tr>
		<% if @member.public %>
		<tr><th>Share</th>
		<td>
			<input type="radio" name="public" value="1" id="public_1" <%= is_checked(default_public, true) %>><label for="public_1">Public</label>
			<input type="radio" name="public" value="0" id="public_0" <%= is_checked(default_public, false) %>><label for="public_0">Private</label>
		</td>
		</tr>
		<% end %>
	</table>
	<div class="submit">
		<input type="submit" value="Subscribe" class="submit_button" id="submit_button">
		<input type="checkbox" id="history_back" style="display:none"><label for="history_back" id="label_history_back" style="display:none">back to the page</label>
	</div>
</div>
<% end %>

<% end %>

</div><!-- /end page -->

<div class="subscribe_help">
	<h3>Hint</h3>
	<p>
		You can subscribe to a feed from anywhere with the <a href="/utility/bookmarklet/">browser button</a>.
	</p>
</div>

</div><!-- /end container -->

<% else %>

<div id="registerbox">
	<div id="registerinbox">
	<h2>Subscribe</h2>
	[% PROCESS errors.inc %]
	<div class="sub-content">
		<form name="subscribe" action="/subscribe/" method="POST">
		Blog or Feed URL:
		<input type="text" name="url" size="30" value="http://"> <input type="submit" value="subscribe">
		</form>
	</div>

	<h3>Help</h3>
		<p>Please input URL of the Web site that wants to subscribe. </p>
		<p>More Easy subscribe way?<br />
			You might like the <a href="/utility/bookmarklet/">Bookmarklet</a>.
		</p>
	</div>
</div>

<% end %>

</div><!-- /content-inner -->
</div><!-- /content -->

<script type="text/javascript">if(typeof init == "function") init();</script>
